/*
 * Map.cpp
 *
 *  Created on: Jan 19, 2012
 *      Author: jacobimo
 */

#include "Map.h"

//ctor
Map::Map(string file)
{
	this->_blockHieght = 0;
	this->_blockWieght = 0;
	this->_mapColumn=0;
	this->_mapRow=0;
	this->_arr =NULL;
	this->_map= NULL;
	this->_filePath =file;
}

//copy ctor
Map::Map(const Map & map)
{
	//init the mambers
	this->_blockHieght= map._blockHieght;
	this->_blockWieght=map._blockWieght;
	this->_filePath=map._filePath;
	this->_mapColumn=map._mapColumn;
	this->_mapRow=map._mapRow;

	//copy the map
	if (map._map!=NULL) {
		this->_map =new Location*[map._mapRow];
		for (int i = 0; i < map._mapRow; ++i) {
			this->_map[i] = new Location[map._mapColumn];
			for (int j = 0; j < map._mapColumn; ++j) {
				this->_map[i][j] = map._map[i][j];
			}
		}
	}

	//copy the path
	for (int i = 0; i < map._path.getCount(); ++i) {
		this->_path[i] =map._path[i];
	}
}

//dtor
Map::~Map() {
	if (this->_map!=NULL) {
		for (int i= 0; i<this->_mapRow; ++i) {
			delete[] this->_map[i];
		}
		delete[] this->_map;
	}
}

//load the file
void Map::loadfile()
{
	//open the file and read row, column and res
	this->_arr = new int*[this->_mapRow];
	for(int i=0;i<this->_mapRow;i++)
		this->_arr[i] = new int[this->_mapColumn];

		//open the file and read row, column and res
	ifstream readMap;
	readMap.open("file");
	string output;

	if (readMap.is_open()) {
	 while (!readMap.eof()) {


	    readMap >> output;
	    //cout<<output;


	 }
	}
	//myReadFile.close();
	//Copy data from file to _arr
}

//get the current map
Location** Map::getMap() const
{
	return this->_map;
}
